<template>
    <el-select v-model="defaultValue"
          :placeholder="placeholder ? placeholder : '请选择' + label"
          multiple filterable @change="changeFun" :disabled="disabled">
          <el-option v-for="i in options" :key="optionsValue ? i[optionsValue] : i.value"
            :label="optionsLabel ? i[optionsLabel] : i.label"
            :value="optionsValue ? i[optionsValue] : i.value">
          </el-option>
        </el-select>
</template>

<script>
  export default {
    props: ["value", "label", "placeholder", "options", "optionsLabel", "optionsValue", "disabled"],
    data() {
      return {
        defaultValue: []
      };
    },
    watch: {
      watchValue: {
        handler(value) {
          if(value){
            this.defaultValue = JSON.parse(value);
          }
        }
      }
    },
    computed: {
      watchValue() {
        return this.value
      }
    },
    mounted() {
    },
    methods: {
        changeFun(value){
          if(value.length==0){
            value = undefined;
          }
          this.$emit('update:value',JSON.stringify(value));
        }
    },
  };
</script>

<style>

</style>